package beerAir;

import java.util.Date;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class OffersView {
	private String firstName;
	private String secondName;
	private Date birthDate;
	private String docType;
	private String docID;
	private Date expDate;
	private String baggage;
	private String error;
		
	public String getError() {
		return error;
	}
	public void setError(String error) {
		this.error = error;
	}
	
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getSecondName() {
		return secondName;
	}
	public void setSecondName(String secondName) {
		this.secondName = secondName;
	}
	public Date getBirthDate() {
		return birthDate;
	}
	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}
	public String getDocType() {
		return docType;
	}
	public void setDocType(String docType) {
		this.docType = docType;
	}
	public String getDocID() {
		return docID;
	}
	public void setDocID(String docID) {
		this.docID = docID;
	}
	public Date getExpDate() {
		return expDate;
	}
	public void setExpDate(Date expDate) {
		this.expDate = expDate;
	}
	public String getBaggage() {
		return baggage;
	}
	public void setBaggage(String baggage) {
		this.baggage = baggage;
	}
	public String showTimetable() {
		return("Timetable");
	}
	public String showPayment(){
		
		User u = new User();
		
		if(firstName.equals(""))
			error="ERROR:No first name inserted";
		if(secondName.equals(""))
			error="ERROR:No second name inserted";
		if(birthDate == null)
			error="ERROR:Invalid Birth Date";
		if(docType.equals(null))
			error="ERROR:Invalid Document Type";
		if(u.checkDoc(docType, docID)==false)
			error="ERROR:Invalid Document ID";
		if(u.checkExp(expDate)==false)
			error="ERROR:Invalid Expiration date";
		if(baggage.equals(null))
			error="ERROR:Invalid Baggage Type";
		
		if(error!=null){
			return("Offers");
		}
		u.setFirstName(firstName);
		u.setSecondName(secondName);
		u.setBaggage(baggage);
		u.setBirthDate(birthDate);
		u.setDocType(docType);
		u.setIdDoc(docID);
		u.setExpDate(expDate);
		
		BookingController b = new BookingController();
		error = b.insertUser(u);
		
		if(error==null){
			return("Payment");
		}
		return ("Offers");
	}

}
